package com.tech.koufu.ui.adapter;

import java.util.ArrayList;

import com.tech.koufu.R;
import com.tech.koufu.model.CompetitionGroupUser;
import com.tech.koufu.ui.adapter.ExpertsShowAdapter.ViewHolder;

import android.content.Context;
import android.view.LayoutInflater;
import android.view.View;
import android.view.ViewGroup;
import android.widget.BaseAdapter;
import android.widget.Button;
import android.widget.ImageView;
import android.widget.TextView;

public class RankCompetorAdapter extends BaseAdapter {
	private Context context;  
	private LayoutInflater mInflater = null; 
	public ArrayList<CompetitionGroupUser> datas;
	public  RankCompetorAdapter(Context context) {
		this.context = context;
		this.mInflater = LayoutInflater.from(context);
		datas = new ArrayList<CompetitionGroupUser>();
	}
	@Override
	public int getCount() {
		if(datas!=null){
		return datas.size();
		}else{
			return 0;
		}
	}

	@Override
	public Object getItem(int position) {
		if(datas!=null){ 
			return datas.get(position);
		}else{
			return null;
		}
	}

	@Override
	public long getItemId(int position) {
		return position;
	}

	@Override
	public View getView(int position, View convertView, ViewGroup parent) {
		 ViewHolder holder = null;  
         //如果缓存convertView为空，则需要创建View  
         if(convertView == null)  
         {  
             holder = new ViewHolder();  
             //根据自定义的Item布局加载布局  
             convertView = mInflater.inflate(R.layout.lv_item_simcompetitor, parent,false);  
             holder.txt_rankid = (TextView)convertView.findViewById(R.id.txt_rankid);  
             holder.txt_competitor_name = (TextView)convertView.findViewById(R.id.txt_competitor_name);  
             holder.txt_total_profit = (TextView)convertView.findViewById(R.id.txt_total_profit);    
             
             //将设置好的布局保存到缓存中，并将其设置在Tag里，以便后面方便取出Tag  
             convertView.setTag(holder);  
         }else  
         {  
             holder = (ViewHolder)convertView.getTag();  
         }  
         if(position==0){
        	 holder.txt_rankid.setTextColor(this.context.getResources().getColor(R.color.TextColorRed_FD0000));
         }else if(position==1){
        	 holder.txt_rankid.setTextColor(this.context.getResources().getColor(R.color.txtColorGreen_21d400));
         }else if(position ==2){
        	 holder.txt_rankid.setTextColor(this.context.getResources().getColor(R.color.txtColorYellow_dd9800));
         }else{
        	 holder.txt_rankid.setTextColor(this.context.getResources().getColor(R.color.bgBlackColor_63));
         }
         holder.txt_rankid.setText(position+".");
         CompetitionGroupUser cgu = (CompetitionGroupUser) getItem(position);
         holder.txt_competitor_name.setText(cgu.userName);
         holder.txt_total_profit.setText(cgu.zongUp);
         
         return convertView;
	}
	static class ViewHolder  
    {    
		public TextView txt_rankid;
        public TextView txt_competitor_name;  
        public TextView txt_total_profit;  
        
    }  
}
